package com.example.lark.common.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 用于接收飞书API的响应信息
 *
 * @param <T> 泛型
 */
@Data
public class LarkSuiteResult<T> implements Serializable {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    public boolean isSuccess() {
        return code == 0;
    }

    public static <T> LarkSuiteResult<T> success() {
        LarkSuiteResult<T> result = new LarkSuiteResult<T>();
        result.code = 0;
        result.msg = "成功";
        return result;
    }

    public static <T> LarkSuiteResult<T> success(T object) {
        LarkSuiteResult<T> result = success();
        result.data = object;
        return result;
    }

    public static <T> LarkSuiteResult<T> setResult(Integer code, String msg) {
        LarkSuiteResult<T> result = new LarkSuiteResult<T>();
        result.code = code;
        result.msg = msg;
        return result;
    }
}
